"use strict";

/**
 * @auther wtfssd
 * Created by wtfssd on 2017/10/27
 */
import * as React from 'react'
import {commonStyles} from "../assets/styles/common";
import MyIcon from "./icon";

import MyText from "./MyText";
import {NavRightButtonProps} from "./index";

const {View, TouchableOpacity} = require('react-native');

const {Actions} = require('react-native-router-flux');

class NavRightButton extends React.Component<NavRightButtonProps, any> {

    static defaultProps = {
        icon: {} ,
        onPress:()=>{}
    };
    renderChildren = ()=>{
        if(typeof this.props.children === 'string'){
            return (
                <View style={commonStyles.backButton}>
                    <MyText color='#fff' style={[this.props.textStyle]}>{this.props.children}</MyText>
                </View>
            )
        }else{
            return(
                <View style={commonStyles.backButton}>
                    {this.props.children}
                </View>
            )
        }
    };

    render() {
        return (
            <TouchableOpacity onPress={this.props.onPress}>
                {this.props.children?this.renderChildren():
                    <View style={commonStyles.backButton}>
                        <MyIcon {...this.props.icon}/>
                    </View>}
            </TouchableOpacity>

        );
    }
}


export default NavRightButton;